package com.geek.gkpush.framework.event.factory;

import com.geek.gkpush.framework.event.model.EventMsgContext;
import com.geek.gkpush.framework.event.model.EventMsgDTO;

import java.util.List;
import java.util.stream.Collectors;

/**
 * <h1>创建事件消息上下文的工厂类。</h1><br/>
 *
 * <h1><br/><a href="https://u.geekbang.org/subject/arch3/100614201">Java 业务架构实战营：https://u.geekbang.org/subject/arch3/100614201</a></h1><br/><h1><a href="https://gitee.com/ylimhhmily/BizArchPracticeCamp">Java 业务架构实战营代码地址：https://gitee.com/ylimhhmily/BizArchPracticeCamp</a></h1><br/><h1><a href="https://u.geekbang.org/subject/java4th/1001148?source=app_share">高级 Java 工程体系课 2023 版：https://u.geekbang.org/subject/java4th/1001148?source=app_share</a></h1><br/><h1><a href="https://time.geekbang.org/column/intro/100312101?tab=catalog">Dubbo 源码剖析与实战：https://time.geekbang.org/column/intro/100312101?tab=catalog</a></h1>
 *
 * @author hmilyylimh
 *         ^_^
 * @version 0.0.1
 *         ^_^
 * @date 2023/10/2
 *
 */
public class EventMsgContextFactory {

    /**
     * <h2>根据模型对象创建消息上下文对象。</h2>
     *
     * @param reqMsgDTO
     * @return
     */
    public static EventMsgContext create(EventMsgDTO reqMsgDTO) {
        EventMsgContext ctx = new EventMsgContext();

        ctx.setId(reqMsgDTO.getId());
        ctx.setBizId(reqMsgDTO.getBizId());
        ctx.setBizType(reqMsgDTO.getBizType());

        ctx.setMsgContent(reqMsgDTO.getMsgContent());
        ctx.setPushStatus(reqMsgDTO.getPushStatus());
        ctx.setCreateTime(reqMsgDTO.getCreateTime());

        return ctx;
    }

    /**
     * <h2>根据模型对象创建消息上下文对象。</h2>
     *
     * @param reqMsgList
     * @return
     */
    public static List<EventMsgContext> createList(List<EventMsgDTO> reqMsgList) {
        List<EventMsgContext> ctxList = reqMsgList.stream()
                .map(reqMsgDTO -> create(reqMsgDTO))
                .collect(Collectors.toList());

        return ctxList;
    }
}